//
//  AXFDaiboCollectionViewCell.m
//  aixinfeng005
//
//  Created by 代波 on 16/10/11.
//  Copyright © 2016年 BBSWaitting. All rights reserved.
//

#import "AXFDaiboCollectionViewCell.h"
#import "AXFDaiboModel.h"

#define marginEight 8
#define marginFour 4
#define CLength 60
#define marginCW 20

@interface AXFDaiboCollectionViewCell ()

@property (nonatomic, strong) UIImageView *iconView;

@property (nonatomic, strong) UILabel *nameLabel;

@property (nonatomic, strong) UILabel *priceLabel;

@property (nonatomic, strong) UILabel *descLabel;

@property (nonatomic, strong) UIView *descView;

@end

@implementation AXFDaiboCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.textColor = [UIColor blueColor];
    nameLabel.textAlignment = NSTextAlignmentCenter;
    nameLabel.font = [UIFont systemFontOfSize:15];
    
    [self.contentView addSubview:nameLabel];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(marginEight*3);
        make.top.offset(marginEight);
    }];
    
    UILabel *priceLabel = [[UILabel alloc] init];
    priceLabel.textColor = [UIColor grayColor];
    priceLabel.textAlignment = NSTextAlignmentCenter;
    priceLabel.font = [UIFont systemFontOfSize:12];
    
    [self.contentView addSubview:priceLabel];
    
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(marginEight*3);
        make.top.equalTo(nameLabel.mas_bottom).offset(marginFour);
    }];
    
    UIImageView *iconView = [[UIImageView alloc] init];
    
    [self.contentView addSubview:iconView];
    
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(marginEight*3);
        make.top.equalTo(priceLabel.mas_bottom).offset(marginEight);
        make.width.height.offset(CLength);
    }];
        
    UIView *descView = [[UIView alloc] init];
    descView.backgroundColor = [UIColor redColor];
    descView.layer.cornerRadius = 12;
    descView.layer.masksToBounds = YES;
    
    [self.contentView addSubview:descView];
    
    [descView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(CLength+marginEight*2);
        make.top.equalTo(priceLabel.mas_bottom).offset(marginEight);
        make.width.height.offset(24);
    }];
    
    UILabel *descLabel = [[UILabel alloc] init];
    descLabel.backgroundColor = [UIColor clearColor];
    descLabel.textColor = [UIColor whiteColor];
    descLabel.textAlignment = NSTextAlignmentCenter;
    descLabel.font = [UIFont systemFontOfSize:8];
    descLabel.numberOfLines= 2;

    [self.contentView addSubview:descLabel];
    
    [descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(CLength+marginEight*2+2);
        make.top.equalTo(priceLabel.mas_bottom).offset(marginEight+2);
        make.width.mas_lessThanOrEqualTo(22);
    }];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor lightGrayColor];
    
    [self.contentView addSubview:lineView];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(0);
        make.width.offset(1);
        make.top.bottom.offset(0);
    }];
    
    self.iconView = iconView;
    self.nameLabel = nameLabel;
    self.priceLabel = priceLabel;
    self.descLabel = descLabel;
    self.descView = descView;
}

- (void)setDaiboModel:(AXFDaiboModel *)daiboModel
{
    _daiboModel = daiboModel;
    
    self.iconView.image = [UIImage imageNamed:daiboModel.icon];
    self.nameLabel.text = daiboModel.name;
    self.priceLabel.text = daiboModel.price;
    self.descLabel.text = daiboModel.desc;
    if (self.descLabel.text.length == 0) {
        self.descView.hidden = YES;
    }
 
}

@end
